package com.smasher.component.activity

import android.util.Log
import android.view.View
import com.smasher.component.R
import com.smasher.component.databinding.ActivityEncryptBinding
import com.smasher.core.encrypt.symmetric.AESKeySize
import com.smasher.core.encrypt.symmetric.AESUtil
import com.smasher.core.utils.TouchUtil
import com.smasher.widget.base.BaseActivity

class EncryptActivity : BaseActivity(), View.OnClickListener {

    private lateinit var mBinding: ActivityEncryptBinding

    private var aesKey = ""
    private var aesIv = ""

    private var encrypt = ""
    private var decrypt = ""

    override fun getRootView(): View {
        mBinding = ActivityEncryptBinding.inflate(layoutInflater)
        return mBinding.root
    }

    override fun initView() {

        mBinding.target.setOnClickListener(this)
        mBinding.buttonGenerate.setOnClickListener(this)
        mBinding.buttonWay1Encrypt.setOnClickListener(this)
        mBinding.buttonWay1Dencrypt.setOnClickListener(this)
        mBinding.buttonWay2Encrypt.setOnClickListener(this)
        mBinding.buttonWay2Dencrypt.setOnClickListener(this)

    }

    override fun initData() {

    }


    override fun onClick(v: View) {
        if (TouchUtil.isFastTouch()) {
            return
        }
        when (v.id) {
            R.id.target -> {

            }

            R.id.button_generate -> {
                aesKey = AESUtil.generateKey(AESKeySize.SIZE_128)
                Log.i(TAG, "aesKey: $aesKey")
                aesIv = AESUtil.generateIv()
                Log.i(TAG, "aesIv: $aesIv")
            }

            R.id.button_way1_encrypt -> {
                encrypt = AESUtil.encrypt("685210", aesKey, aesIv)
                Log.i(TAG, "encrypt: $encrypt")
            }

            R.id.button_way1_dencrypt -> {
                decrypt = AESUtil.decrypt(encrypt, aesKey, aesIv)
                Log.i(TAG, "decrypt: $decrypt")
            }

            R.id.button_way2_encrypt -> {

            }

            R.id.button_way2_dencrypt -> {

            }

        }
    }

    companion object {
        const val TAG = "Encrypt"
    }
}